/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.biz.manager.transaction.impl;

import java.util.Date;

import org.grayrabbit.pay.core.biz.manager.transaction.TradeHistoryManager;
import org.grayrabbit.pay.core.model.entity.transaction.TradeHistory;
import org.grayrabbit.pay.core.model.enums.TradeEnum;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.grayrabbit.pay.core.model.results.PayResult;
import org.grayrabbit.pay.core.service.transaction.TradeHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeHistoryManagerImpl.java, v 0.1 Fri Jun 01 11:16:04 CST 2012 liyd Exp $
 */
@Component
public class TradeHistoryManagerImpl implements TradeHistoryManager {

    @Autowired
    private TradeHistoryService tradeHistoryService;

    /**
     * 查询业务列表
     * 
     * @param district
     * @return
     */
    public GenericsResult<PageList<TradeHistory>> queryPageList(TradeHistory tradeHistory) {

        GenericsResult<PageList<TradeHistory>> result = new GenericsResult<PageList<TradeHistory>>(
            true);
        PageList<TradeHistory> list = tradeHistoryService.queryPageList(tradeHistory);
        for (TradeHistory history : list) {
            history.setStatusEnum(TradeEnum.getTradeEnum(history.getTradeStatus()));
        }
        result.setResultData(list);

        return result;
    }

    public GenericsResult<PageList<TradeHistory>> queryPageList(TradeHistory tradeHistory,
                                                                Date startDate, Date endDate) {

        GenericsResult<PageList<TradeHistory>> result = new GenericsResult<PageList<TradeHistory>>(
            true);
        PageList<TradeHistory> list = tradeHistoryService.queryPageList(tradeHistory, startDate,
            endDate);
        for (TradeHistory history : list) {
            history.setStatusEnum(TradeEnum.getTradeEnum(history.getTradeStatus()));
        }
        result.setResultData(list);

        return result;
    }

    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public GenericsResult<TradeHistory> getById(Long id) {

        GenericsResult<TradeHistory> result = new GenericsResult<TradeHistory>(true);

        result.setResultData(tradeHistoryService.getById(id));

        return result;

    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     * @return
     */
    public PayResult deleteBatchById(Long[] idArray) {

        PayResult result = new PayResult(true);

        tradeHistoryService.deleteBatchById(idArray);

        return result;
    }

    /**
     * 添加一个对象
     * 
     * @param tradeHistory
     * @return
     */
    public GenericsResult<TradeHistory> insert(TradeHistory tradeHistory) {

        GenericsResult<TradeHistory> result = new GenericsResult<TradeHistory>(true);

        tradeHistoryService.insert(tradeHistory);

        return result;

    }

    /**
     * 更新一个对象
     * 
     * @param tradeHistory
     * @return
     */
    public GenericsResult<Integer> update(TradeHistory tradeHistory) {

        GenericsResult<Integer> result = new GenericsResult<Integer>(true);

        result.setResultData(tradeHistoryService.update(tradeHistory));

        return result;
    }

    /**
     * 删除一个对象
     * 
     * @param tradeHistory
     * @return 
     */
    public PayResult delete(TradeHistory tradeHistory) {

        PayResult result = new PayResult(true);

        tradeHistoryService.delete(tradeHistory);

        return result;
    }

}
